﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void UpdateAPKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE APKOPF SET "
            + "APKMANDANT=:APKMANDANT,"
            + "APKWERK=:APKWERK,"
            + "APKANRKRS=:APKANRKRS,"
            + "APKALFDNR=:APKALFDNR,"
            + "APKSPEZIF=:APKSPEZIF,"
            + "APKSPSTA=:APKSPSTA,"
            + "APKSPGRD=:APKSPGRD,"
            + "APKSTUFE=:APKSTUFE,"
            + "APKABT=:APKABT,"
            + "APKVERSAE=:APKVERSAE,"
            + "APKVERSZL=:APKVERSZL,"
            + "APKAENDZL=:APKAENDZL,"
            + "APKAENDBEN=:APKAENDBEN,"
            + "APKAENDDAT=:APKAENDDAT,"
            + "APKNEUBEN=:APKNEUBEN,"
            + "APKNEUDAT=:APKNEUDAT,"
            + "APKZUSTAND=:APKZUSTAND,"
            + "APKZUSATZKZ1=:APKZUSATZKZ1,"
            + "APKZUSATZKZ2=:APKZUSATZKZ2,"
            + "APKZUSATZKZ3=:APKZUSATZKZ3,"
            + "APKZUSATZKZ4=:APKZUSATZKZ4,"
            + "APKGZUSKZ1=:APKGZUSKZ1,"
            + "APKGZUSKZ2=:APKGZUSKZ2,"
            + "APKGZUSKZ3=:APKGZUSKZ3,"
            + "APKGZUSKZ4=:APKGZUSKZ4,"
            + "APKKAAGRA=:APKKAAGRA,"
            + "APKKAAGRP=:APKKAAGRP,"
            + "APKGRGRP1=:APKGRGRP1,"
            + "APKGRGRP2=:APKGRGRP2,"
            + "APKGRGRP3=:APKGRGRP3,"
            + "APKGRGRP4=:APKGRGRP4,"
            + "APKGRGRP5=:APKGRGRP5,"
            + "APKGSTUFE=:APKGSTUFE,"
            + "APKGRRAS=:APKGRRAS,"
            + "APKTLVF1=:APKTLVF1,"
            + "APKTLAFOV1=:APKTLAFOV1,"
            + "APKTLAFOB1=:APKTLAFOB1,"
            + "APKTLVF2=:APKTLVF2,"
            + "APKTLAFOV2=:APKTLAFOV2,"
            + "APKTLAFOB2=:APKTLAFOB2,"
            + "APKTLVF3=:APKTLVF3,"
            + "APKTLAFOV3=:APKTLAFOV3,"
            + "APKTLAFOB3=:APKTLAFOB3,"
            + "APKTLVF4=:APKTLVF4,"
            + "APKTLAFOV4=:APKTLAFOV4,"
            + "APKTLAFOB4=:APKTLAFOB4,"
            + "APKTLVF5=:APKTLVF5,"
            + "APKTLAFOV5=:APKTLAFOV5,"
            + "APKTLAFOB5=:APKTLAFOB5,"
            + "APKTLVF6=:APKTLVF6,"
            + "APKTLAFOV6=:APKTLAFOV6,"
            + "APKTLAFOB6=:APKTLAFOB6,"
            + "APKTLVF7=:APKTLVF7,"
            + "APKTLAFOV7=:APKTLAFOV7,"
            + "APKTLAFOB7=:APKTLAFOB7,"
            + "APKMU=:APKMU,"
            + "APKMURLOD=:APKMURLOD,"
            + "APKMUPROD=:APKMUPROD,"
            + "APKMUCTOD=:APKMUCTOD,"
            + "APKMUDTRL=:APKMUDTRL,"
            + "APKMUBIRL=:APKMUBIRL,"
            + "APKVERSZLRL=:APKVERSZLRL,"
            + "APKVERSBEN=:APKVERSBEN,"
            + "APKFILLER=:APKFILLER "
                + " WHERE  "
                + "  APKMANDANT=:APKMANDANT AND APKANRKRS=:APKANRKRS  AND APKALFDNR=:APKALFDNR ";

            or1.Parameters.Add("APKMANDANT", OracleType.NVarChar).Value = dwData["APKMANDANT"].ToString();
            or1.Parameters.Add("APKWERK", OracleType.NVarChar).Value = dwData["APKWERK"].ToString();
            or1.Parameters.Add("APKANRKRS", OracleType.NVarChar).Value = dwData["APKANRKRS"].ToString();
            or1.Parameters.Add("APKALFDNR", OracleType.NVarChar).Value = dwData["APKALFDNR"].ToString();
            or1.Parameters.Add("APKSPEZIF", OracleType.NVarChar).Value = dwData["APKSPEZIF"].ToString();
            or1.Parameters.Add("APKSPSTA", OracleType.NVarChar).Value = dwData["APKSPSTA"].ToString();
            or1.Parameters.Add("APKSPGRD", OracleType.NVarChar).Value = dwData["APKSPGRD"].ToString();
            or1.Parameters.Add("APKSTUFE", OracleType.NVarChar).Value = dwData["APKSTUFE"].ToString();
            or1.Parameters.Add("APKABT", OracleType.NVarChar).Value = dwData["APKABT"].ToString();
            or1.Parameters.Add("APKVERSAE", OracleType.NVarChar).Value = dwData["APKVERSAE"].ToString();
            or1.Parameters.Add("APKVERSZL", OracleType.NVarChar).Value = dwData["APKVERSZL"].ToString();
            or1.Parameters.Add("APKAENDZL", OracleType.NVarChar).Value = dwData["APKAENDZL"].ToString();
            or1.Parameters.Add("APKAENDBEN", OracleType.NVarChar).Value = dwData["APKAENDBEN"].ToString();
            or1.Parameters.Add("APKAENDDAT", OracleType.NVarChar).Value = dwData["APKAENDDAT"].ToString();
            or1.Parameters.Add("APKNEUBEN", OracleType.NVarChar).Value = dwData["APKNEUBEN"].ToString();
            or1.Parameters.Add("APKNEUDAT", OracleType.NVarChar).Value = dwData["APKNEUDAT"].ToString();
            or1.Parameters.Add("APKZUSTAND", OracleType.NVarChar).Value = dwData["APKZUSTAND"].ToString();
            or1.Parameters.Add("APKZUSATZKZ1", OracleType.NVarChar).Value = dwData["APKZUSATZKZ1"].ToString();
            or1.Parameters.Add("APKZUSATZKZ2", OracleType.NVarChar).Value = dwData["APKZUSATZKZ2"].ToString();
            or1.Parameters.Add("APKZUSATZKZ3", OracleType.NVarChar).Value = dwData["APKZUSATZKZ3"].ToString();
            or1.Parameters.Add("APKZUSATZKZ4", OracleType.NVarChar).Value = dwData["APKZUSATZKZ4"].ToString();
            or1.Parameters.Add("APKGZUSKZ1", OracleType.NVarChar).Value = dwData["APKGZUSKZ1"].ToString();
            or1.Parameters.Add("APKGZUSKZ2", OracleType.NVarChar).Value = dwData["APKGZUSKZ2"].ToString();
            or1.Parameters.Add("APKGZUSKZ3", OracleType.NVarChar).Value = dwData["APKGZUSKZ3"].ToString();
            or1.Parameters.Add("APKGZUSKZ4", OracleType.NVarChar).Value = dwData["APKGZUSKZ4"].ToString();
            or1.Parameters.Add("APKKAAGRA", OracleType.NVarChar).Value = dwData["APKKAAGRA"].ToString();
            or1.Parameters.Add("APKKAAGRP", OracleType.NVarChar).Value = dwData["APKKAAGRP"].ToString();
            or1.Parameters.Add("APKGRGRP1", OracleType.NVarChar).Value = dwData["APKGRGRP1"].ToString();
            or1.Parameters.Add("APKGRGRP2", OracleType.NVarChar).Value = dwData["APKGRGRP2"].ToString();
            or1.Parameters.Add("APKGRGRP3", OracleType.NVarChar).Value = dwData["APKGRGRP3"].ToString();
            or1.Parameters.Add("APKGRGRP4", OracleType.NVarChar).Value = dwData["APKGRGRP4"].ToString();
            or1.Parameters.Add("APKGRGRP5", OracleType.NVarChar).Value = dwData["APKGRGRP5"].ToString();
            or1.Parameters.Add("APKGSTUFE", OracleType.NVarChar).Value = dwData["APKGSTUFE"].ToString();
            or1.Parameters.Add("APKGRRAS", OracleType.NVarChar).Value = dwData["APKGRRAS"].ToString();
            or1.Parameters.Add("APKTLVF1", OracleType.NVarChar).Value = dwData["APKTLVF1"].ToString();
            or1.Parameters.Add("APKTLAFOV1", OracleType.NVarChar).Value = dwData["APKTLAFOV1"].ToString();
            or1.Parameters.Add("APKTLAFOB1", OracleType.NVarChar).Value = dwData["APKTLAFOB1"].ToString();
            or1.Parameters.Add("APKTLVF2", OracleType.NVarChar).Value = dwData["APKTLVF2"].ToString();
            or1.Parameters.Add("APKTLAFOV2", OracleType.NVarChar).Value = dwData["APKTLAFOV2"].ToString();
            or1.Parameters.Add("APKTLAFOB2", OracleType.NVarChar).Value = dwData["APKTLAFOB2"].ToString();
            or1.Parameters.Add("APKTLVF3", OracleType.NVarChar).Value = dwData["APKTLVF3"].ToString();
            or1.Parameters.Add("APKTLAFOV3", OracleType.NVarChar).Value = dwData["APKTLAFOV3"].ToString();
            or1.Parameters.Add("APKTLAFOB3", OracleType.NVarChar).Value = dwData["APKTLAFOB3"].ToString();
            or1.Parameters.Add("APKTLVF4", OracleType.NVarChar).Value = dwData["APKTLVF4"].ToString();
            or1.Parameters.Add("APKTLAFOV4", OracleType.NVarChar).Value = dwData["APKTLAFOV4"].ToString();
            or1.Parameters.Add("APKTLAFOB4", OracleType.NVarChar).Value = dwData["APKTLAFOB4"].ToString();
            or1.Parameters.Add("APKTLVF5", OracleType.NVarChar).Value = dwData["APKTLVF5"].ToString();
            or1.Parameters.Add("APKTLAFOV5", OracleType.NVarChar).Value = dwData["APKTLAFOV5"].ToString();
            or1.Parameters.Add("APKTLAFOB5", OracleType.NVarChar).Value = dwData["APKTLAFOB5"].ToString();
            or1.Parameters.Add("APKTLVF6", OracleType.NVarChar).Value = dwData["APKTLVF6"].ToString();
            or1.Parameters.Add("APKTLAFOV6", OracleType.NVarChar).Value = dwData["APKTLAFOV6"].ToString();
            or1.Parameters.Add("APKTLAFOB6", OracleType.NVarChar).Value = dwData["APKTLAFOB6"].ToString();
            or1.Parameters.Add("APKTLVF7", OracleType.NVarChar).Value = dwData["APKTLVF7"].ToString();
            or1.Parameters.Add("APKTLAFOV7", OracleType.NVarChar).Value = dwData["APKTLAFOV7"].ToString();
            or1.Parameters.Add("APKTLAFOB7", OracleType.NVarChar).Value = dwData["APKTLAFOB7"].ToString();
            or1.Parameters.Add("APKMU", OracleType.NVarChar).Value = dwData["APKMU"].ToString();
            or1.Parameters.Add("APKMURLOD", OracleType.NVarChar).Value = dwData["APKMURLOD"].ToString();
            or1.Parameters.Add("APKMUPROD", OracleType.NVarChar).Value = dwData["APKMUPROD"].ToString();
            or1.Parameters.Add("APKMUCTOD", OracleType.NVarChar).Value = dwData["APKMUCTOD"].ToString();
            or1.Parameters.Add("APKMUDTRL", OracleType.NVarChar).Value = dwData["APKMUDTRL"].ToString();
            or1.Parameters.Add("APKMUBIRL", OracleType.NVarChar).Value = dwData["APKMUBIRL"].ToString();
            or1.Parameters.Add("APKVERSZLRL", OracleType.NVarChar).Value = dwData["APKVERSZLRL"].ToString();
            or1.Parameters.Add("APKVERSBEN", OracleType.NVarChar).Value = dwData["APKVERSBEN"].ToString();
            or1.Parameters.Add("APKFILLER", OracleType.NVarChar).Value = dwData["APKFILLER"].ToString();
            Connect2Proxy(or1);
        }
        public DataSet QueryAPKOPF(string apkrs, string apdnr)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM APKOPF WHERE  "
            + "  APKMANDANT='00' AND APKANRKRS=:APKANRKRS AND APKALFDNR=:APKALFDNR";

            or1.Parameters.Add("APKANRKRS", OracleType.NVarChar).Value = apkrs;
            or1.Parameters.Add("APKALFDNR", OracleType.NVarChar).Value = apdnr;

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "APKOPF";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public DataSet QueryAPKOPF(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM APKOPF WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT P.* FROM APKOPF P "
                        + "  WHERE APKMANDANT=:APKMANDANT ";
                    or1.Parameters.Add("APKMANDANT", OracleType.NVarChar).Value = dwData["APKMANDANT"];  
         
                    break;
                case 9999:
                    or1.CommandText = "SELECT * FROM APKOPF ORDER BY 1,2,3,4";
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "APKOPF";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
    }
}
